package com.hctg.forced2sleep.easy_window;

import android.app.Application;
import android.os.Build;
import android.view.WindowManager;

import com.actor.myandroidframework.utils.LogUtils;
import com.hctg.forced2sleep.service.MyAccessibilityService;
import com.hctg.forced2sleep.utils.AccessibilityUtils;
import com.hctg.forced2sleep.utils.FloatViewUtils;
import com.hjq.window.EasyWindow;

/**
 * description: 轮轮哥的 EasyWindow 不能覆盖系统设置, 改一下
 *
 * @author : ldf
 * date       : 2024/10/22 on 15
 * @version 1.0
 */
public class EasyWindow2<X extends EasyWindow<?>> extends EasyWindow<X> {

//    public EasyWindow2(Activity activity) {
//        super(activity);
//    }

    public EasyWindow2(Application application) {
        super(application);
        LogUtils.error(getClass().getName());
        setWindowManager(FloatViewUtils.getWindowManager());

        boolean isRunning = AccessibilityUtils.isAccessibilitySettingsOn(MyAccessibilityService.class);
        //                                              22
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && isRunning) {
            //全局的悬浮窗
            setWindowType(WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {    //26
            setWindowType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        } else {
            setWindowType(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY);
        }

        // 设置成全局的悬浮窗，注意需要先申请悬浮窗权限，推荐使用：https://github.com/getActivity/XXPermissions
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//            setWindowType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
//        } else {
//            setWindowType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
//        }


        //这儿设置全屏, 无效.
//        addWindowFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
//        setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
    }
}
